﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AdminPages_AddMovie : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_AddMovie_Click(object sender, EventArgs e)
    {


        //Insert Movie
          DVDTableAdapters.MovieTableAdapter ta = new DVDTableAdapters.MovieTableAdapter();
          ta.Insert(txt_Movietitle.Text, txt_MovieDescription.Text, Convert.ToInt32(txt_Length.Text), txt_Director.Text, false,Convert.ToDateTime(txt_AvailabilityDate.Text),0,0);
  
        //GetMovieID
        int movieID=(int)ta.GetMovieIDbyTitle(txt_Movietitle.Text);
        
        //Insert First Category
        int cat11 = Convert.ToInt32(ddl_Cat1.SelectedItem.Value);
        if(cat11>1)
        {
            DVDTableAdapters.CategoryMovieTableAdapter ta1 = new DVDTableAdapters.CategoryMovieTableAdapter();
            ta1.Insert(cat11,movieID);
        }

        //Insert Second Category    
        int cat21 = Convert.ToInt32(ddl_Cat2.SelectedItem.Value);
        if(cat21>1)
        {
            DVDTableAdapters.CategoryMovieTableAdapter ta1 = new DVDTableAdapters.CategoryMovieTableAdapter();
            ta1.Insert(cat21,movieID);
        }
        Response.Redirect("~/Movie.aspx?MovieId="+movieID);
    }
}